<?php
/** 
 * EGP Framework
 *
 * LICENSE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 */

!defined('EGP_LIB_DIR') && die('Access Deny!');

/**
 * HTML 编辑器抽像类
 *
 * @package    helper
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 */
abstract class EGP_View_Helper_Editor_Abstract extends EGP_View_Helper_Abstract
{

    /**
     * 编辑器名称 [name&id]
     *
     * @var string
     */
    protected $_name = 'content';

    /**
     * 显示宽度
     *
     * @var string
     */
    protected $_width = '99%';

    /**
     * 显示高度
     *
     * @var string
     */
    protected $_height = '300';

    /**
     * 编辑器值
     *
     * @var string
     */
    protected $_value = '';

    /**
     * 风格样式
     *
     * @var string
     */
    protected $_style = '';

    /**
     * 编辑器根路径
     *
     * @var string
     */
    protected $_basePath = '/';

    /**
     * 初始化方法
     *
     * @param  array  $config
     * @return EGP_View_Helper_Editor_Abstract
     */
    public function init(array $config = array())
    {
        foreach ($config as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (method_exists($this, $method)) {
                $this->$method($value);
            }
        }
        return $this;
    }

    /**
     * 设置编辑器名称
     *
     * @param  string  $name
     * @return EGP_View_Helper_Editor_Abstract
     */
    public function setName($name)
    {
        $this->_name = (string) $name;
        return $this;
    }

    /**
     * 设置编辑器高度
     *
     * @param  string  $width
     * @return EGP_View_Helper_Editor_Abstract
     */
    public function setWidth($width)
    {
        $this->_width = $width;
        return $this;
    }

    /**
     * 设置编辑器高度
     *
     * @param  string  $height
     * @return EGP_View_Helper_Editor_Abstract
     */
    public function setHeight($height)
    {
        $this->_height = $height;
        return $this;
    }

    /**
     * 设置编辑器值
     *
     * @param  string  $value
     * @return EGP_View_Helper_Editor_Abstract
     */
    public function setValue($value)
    {
        $this->_value = htmlspecialchars($value);
        return $this;
    }

    /**
     * 设置编辑器显示风格/样式
     *
     * @param  string  $style
     * @return EGP_View_Helper_Editor_Abstract
     */
    public function setStyle($style)
    {
        $this->_style = (string) $style;
        return $this;
    }

    /**
     * 设置编辑器根路径
     *
     * @param  string  $basePath
     * @return EGP_View_Helper_Editor_Abstract
     */
    public function setBasePath($basePath)
    {
        $this->_basePath = (string) $basePath;
        return $this;
    }

    /**
     * 输出 HTML 代码
     *
     * @return string
     */
    abstract public function __toString();

}